import {
  Count,
  CountSchema,
  Filter,
  repository,
  Where,
} from '@loopback/repository';
import {
  post,
  param,
  get,
  getFilterSchemaFor,
  getWhereSchemaFor,
  patch,
  put,
  del,
  requestBody,
} from '@loopback/rest';
import { Forward } from '../models';
import { ForwardRepository } from '../repositories';

export class ForwardController {
  constructor(
    @repository(ForwardRepository)
    public forwardRepository: ForwardRepository,
  ) { }

  @post('/forwards', {
    responses: {
      '200': {
        description: 'Forward model instance',
        content: { 'application/json': { schema: { 'x-ts-type': Forward } } },
      },
    },
  })
  async create(@requestBody() forward: Forward): Promise<Forward> {
    return await this.forwardRepository.create(forward);
  }

  @get('/forwards/count', {
    responses: {
      '200': {
        description: 'Forward model count',
        content: { 'application/json': { schema: CountSchema } },
      },
    },
  })
  async count(
    @param.query.object('where', getWhereSchemaFor(Forward)) where?: Where,
  ): Promise<Count> {
    return await this.forwardRepository.count(where);
  }

  @get('/forwards', {
    responses: {
      '200': {
        description: 'Array of Forward model instances',
        content: {
          'application/json': {
            schema: { type: 'array', items: { 'x-ts-type': Forward } },
          },
        },
      },
    },
  })
  async find(
    @param.query.object('filter', getFilterSchemaFor(Forward)) filter?: Filter,
  ): Promise<Forward[]> {
    return await this.forwardRepository.find(filter);
  }

  @patch('/forwards', {
    responses: {
      '200': {
        description: 'Forward PATCH success count',
        content: { 'application/json': { schema: CountSchema } },
      },
    },
  })
  async updateAll(
    @requestBody() forward: Forward,
    @param.query.object('where', getWhereSchemaFor(Forward)) where?: Where,
  ): Promise<Count> {
    return await this.forwardRepository.updateAll(forward, where);
  }

  @get('/forwards/{id}', {
    responses: {
      '200': {
        description: 'Forward model instance',
        content: { 'application/json': { schema: { 'x-ts-type': Forward } } },
      },
    },
  })
  async findById(@param.path.number('id') id: number): Promise<Forward> {
    return await this.forwardRepository.findById(id);
  }

  @patch('/forwards/{id}', {
    responses: {
      '204': {
        description: 'Forward PATCH success',
      },
    },
  })
  async updateById(
    @param.path.number('id') id: number,
    @requestBody() forward: Forward,
  ): Promise<void> {
    await this.forwardRepository.updateById(id, forward);
  }

  @put('/forwards/{id}', {
    responses: {
      '204': {
        description: 'Forward PUT success',
      },
    },
  })
  async replaceById(
    @param.path.number('id') id: number,
    @requestBody() forward: Forward,
  ): Promise<void> {
    await this.forwardRepository.replaceById(id, forward);
  }

  @del('/forwards/{id}', {
    responses: {
      '204': {
        description: 'Forward DELETE success',
      },
    },
  })
  async deleteById(@param.path.number('id') id: number): Promise<void> {
    await this.forwardRepository.deleteById(id);
  }
}
